package com.sellerSystem.aspect;

import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.springframework.stereotype.Controller;

import com.sellerSystem.util.BaseUtil;
import com.sellerSystem.vo.Seller;

@Aspect
@Controller
public class PsdAspect {
	private final String loginPc = "execution(* com.sellerSystem.service.SellerManager.login(..))";

	private final String registPc = "execution(* com.sellerSystem.service.SellerManager.regist(..))";
	private final String modifyPsd = "execution(* com.sellerSystem.service.SellerManager.modifyPsd(..))";

	@Around(loginPc)
	public Object loginMdProcess(ProceedingJoinPoint point) {
		Object o = null;
		String sellerPsd = (String) point.getArgs()[1];
		try {
			o = point.proceed(new Object[] { point.getArgs()[0],
					BaseUtil.Md(sellerPsd, "MD5") });
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}

		return o;
	}
	@Around(modifyPsd)
	public Object modifyPsdMdProcess(ProceedingJoinPoint point) {
		Object o = null;
		String sellerPsd = (String) point.getArgs()[1];
		try {
			o = point.proceed(new Object[] { point.getArgs()[0],
					BaseUtil.Md(sellerPsd, "MD5") });
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
		return o;
	}

	@Around(registPc)
	public Object registMdProcess(ProceedingJoinPoint jp){
		Object o=null;
		Seller seller=(Seller)jp.getArgs()[0];
		seller.setSellerPsd(BaseUtil.Md(seller.getSellerPsd(), "md5"));
		try {
			o=jp.proceed();
		} catch (Throwable e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return o;
	}
}
